#ifndef __PCF8523_CLASS_H_
#define __PCF8523_CLASS_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <iostream>
#include "wiringPi.h"

using namespace std;

class DateTime
{
		friend ostream & operator<<(ostream & out,DateTime& dt);
public:
	DateTime();
	DateTime(int _y,int _m,int _d,int _hour,int _min,int _sec);
	DateTime(const DateTime& dt);
	DateTime& operator=(const DateTime& dt);
	~DateTime();

	int Year();
	int Month();
	int Day();
	int Week();
	int Hour();
	int Minute();
	int Second();

private:
	int y,m,d,w,hour,min,sec;
};

#define RTC_REG_SEC 0x03
#define RTC_REG_MIN 0x04
#define RTC_REG_HOUR 0x05
#define RTC_REG_DAY 0x06
#define RTC_REG_WEEK 0x07
#define RTC_REG_MON  0x08
#define RTC_REG_YEAR 0x09

class PCF8523 
{
public:
	static void printTime(DateTime& dt);

	PCF8523(int addr=0x68);
	~PCF8523();

	DateTime now();
	DateTime readTime();
	void setTime(DateTime& dt);
	void setTime(int y,int m,int d,int hour,int min,int sec);
	bool isRunning();
	void setDefault(); // default datetime:2017-12-20 00:00:00

private:
	int mI2cAddr;
	int mFd;
};

#endif

